package travelDream.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.apache.commons.codec.digest.DigestUtils;

import travelDream.ejb.Gruppo;
import travelDream.ejb.UtenteDTO;



/**
 * Entity implementation class for Entity: UserEntity
 *
 */
@Entity
@Table(name="utente")
@NamedQueries({
	@NamedQuery(name=Utente.FIND_ALL,query="SELECT u FROM Utente u "),
	@NamedQuery(name = "Utente.findByNickname", query = "SELECT u FROM Utente u WHERE u.nickname = :nickname"),
	@NamedQuery(name = "Untente.findById", query = "SELECT u FROM Utente u WHERE u.idUtente = :idUtente")
	})
public class Utente implements Serializable {
	
	private static final long serialVersionUID = 1L;
	public static final String FIND_ALL = "User.findAll";
	
	@Id
	private String nickname;
	
	private int idUtente;
	
	private int eta;
	 
	private String password; 
		
	private String email;
	
	@ElementCollection(targetClass = Gruppo.class)
    @CollectionTable(name = "utenti_gruppi",
                    joinColumns = @JoinColumn(name = "nickname"))
    @Enumerated(EnumType.STRING)
    @Column(name="groupname")
    private List<Gruppo> gruppo;
	
	
	public Utente() {
	}
	
	public Utente (UtenteDTO utente){
		this.eta = utente.getEta();
		this.nickname = utente.getNickname();
		this.password = DigestUtils.sha256Hex(utente.getPassword());   
		this.email = utente.getEmail();
			
	}
	
	public int getIdUtente() {
		return idUtente;
	}

	public void setIdUtente(int idUtente) {
		this.idUtente = idUtente;
	}
	
	
	/**
	 * @return the eta
	 */
	public int getEta() {
		return eta;
	}

	/**
	 * @param eta the eta to set
	 */
	public void setEta(int eta) {
		this.eta = eta;
	}
	
	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	
	public List<Gruppo> getGruppo() {
        return gruppo;
    }
 
    public void setGruppo(List<Gruppo> gruppo) {
        this.gruppo = gruppo;
    }

	
}